package com.qst.shopdb;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.qst.db.DBmanager;

public class Good {
	private int id;
	private String name;
	private BigDecimal price;
	private int num;
	private PreparedStatement psmt;
	private ResultSet rs;
	private Connection conn;
	Scanner sc = new Scanner(System.in);
	public Good() {
		
	}
	
	public Good(int id,String name,BigDecimal price,int num) {
		this.id=id;
		this.name=name;
		this.num=num;
		this.price=price;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public BigDecimal getPrice() {
		return price;
	}
	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	public int getNum() {
		return num;
	}
	public void setNum(int num) {
		this.num = num;
	}
	public ArrayList<Good> getGoodList() {
		ArrayList <Good> list = new ArrayList<Good>();
		try {	
			conn=DBmanager.getConn();
			String sql = "select * from good";
			psmt = (PreparedStatement) conn.prepareStatement(sql);
			rs = psmt.executeQuery();
			while(rs.next()) {
				Good gd = new Good(rs.getInt(1),rs.getString(2),rs.getBigDecimal(3),rs.getInt(4));
				list.add(gd);
				
			}
			conn.close();
			psmt.close();
			rs.close();
			} catch (SQLException e) {
			// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		return list;
	}
	
}


